﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ERP_RORZE_SYSTEM;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class panel_F4DirectIndirect : UserControl
    {
        private INISettings mySetting;
        private SqlConnection myConnection;
        
        public panel_F4DirectIndirect()
        {
            InitializeComponent();            

            this.mySetting = new INISettings();
            this.myConnection = new SqlConnection(mySetting.SQLConnectionString);
            this.subGroup.SelectedIndex = 0;
            this.yearText.Text = DateTime.Now.Year.ToString();

            Dictionary<string, string> SubList = new Dictionary<string, string>() { {"RVASS", "RV Assembly"},
            {"RVINS", "RV Ins"}, {"RBARM", "Robot Arm"}, {"RBINS", "Robot Ins"}, {"RBROT", "Robot Rotation"}, 
            {"RBZ", "Robot Z"}, {"SYSASS", "System Assembly"}, {"SYSINS", "System Ins"}, {"WRVBW", "Wire - RV Box Wire"}, 
            {"WRBUB", "Wire - RB Unit Box"}, {"WRSW", "Wire - System Wire"}, {"OFF", "Office"}};

            foreach (string key in SubList.Keys)
            {
                ComboboxItem item = new ComboboxItem();
                item.Value = key;
                item.Text = SubList[key];
                this.subGroupID.Properties.Items.Add(item);
            }

            this.subGroupLabel.Visible = false;
            this.subGroupID.Visible = false;

            this.subGroup.SelectedIndexChanged += subGroup_SelectedIndexChanged;
        }

        void subGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.subGroup.SelectedIndex == 5)
            {
                this.subGroupLabel.Visible = true;
                this.subGroupID.Visible = true;
            }
            else
            {
                this.subGroupLabel.Visible = false;
                this.subGroupID.Visible = false;
            }
        }

        private void buttonView_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.yearText.Text.Trim()))
            {
                MessageBox.Show("Please enter Year to view report");
            }
            else
            {
                switch (this.subGroup.SelectedIndex)
                {
                    case 0:
                        reportDocument.DocumentSource = null;
                        rpt_F4DirectIndirect F4DirectIndirect = new rpt_F4DirectIndirect();
                        F4DirectIndirect.year = this.yearText.Text.Trim();
                        F4DirectIndirect.LoadData();
                        F4DirectIndirect.CreateDocument();
                        reportDocument.DocumentSource = F4DirectIndirect;
                        break;                        
                    case 1:
                        reportDocument.DocumentSource = null;
                        rpt_F4DirectIndirectRV F4DirectIndirectRV = new rpt_F4DirectIndirectRV();
                        F4DirectIndirectRV.year = this.yearText.Text.Trim();
                        F4DirectIndirectRV.LoadData();
                        F4DirectIndirectRV.CreateDocument();
                        reportDocument.DocumentSource = F4DirectIndirectRV;
                        break;
                    case 2:
                        reportDocument.DocumentSource = null;
                        rpt_F4DirectIndirectRobot F4DirectIndirectRobot = new rpt_F4DirectIndirectRobot();
                        F4DirectIndirectRobot.year = this.yearText.Text.Trim();
                        F4DirectIndirectRobot.LoadData();
                        F4DirectIndirectRobot.CreateDocument();
                        reportDocument.DocumentSource = F4DirectIndirectRobot;
                        break;
                    case 3:
                        reportDocument.DocumentSource = null;
                        rpt_F4DirectIndirectSystem F4DirectIndirectSystem = new rpt_F4DirectIndirectSystem();
                        F4DirectIndirectSystem.year = this.yearText.Text.Trim();
                        F4DirectIndirectSystem.LoadData();
                        F4DirectIndirectSystem.CreateDocument();
                        reportDocument.DocumentSource = F4DirectIndirectSystem;
                        break;
                    case 4:
                        reportDocument.DocumentSource = null;
                        rpt_F4DirectIndirectWire F4DirectIndirectWire = new rpt_F4DirectIndirectWire();
                        F4DirectIndirectWire.year = this.yearText.Text.Trim();
                        F4DirectIndirectWire.LoadData();
                        F4DirectIndirectWire.CreateDocument();
                        reportDocument.DocumentSource = F4DirectIndirectWire;
                        break;
                    case 5:
                        if (this.subGroupID.SelectedIndex < 0)
                        {
                            MessageBox.Show("Please select Sub-Group to view report");
                        }
                        else
                        {
                            ComboboxItem sub = (ComboboxItem)this.subGroupID.SelectedItem;
                            reportDocument.DocumentSource = null;
                            rpt_F4DirectIndirectSubGroup F4DirectIndirectSubGroup = new rpt_F4DirectIndirectSubGroup();
                            F4DirectIndirectSubGroup.year = this.yearText.Text.Trim();
                            F4DirectIndirectSubGroup.sub_group = sub.Value.ToString();                            
                            F4DirectIndirectSubGroup.LoadData();
                            F4DirectIndirectSubGroup.CreateDocument();
                            reportDocument.DocumentSource = F4DirectIndirectSubGroup;
                        }
                        break;
                }                
            }  
        }

        private void buttonTurnOver_Click(object sender, EventArgs e)
        {
            frm_F5TurnOver turnoverForm = new frm_F5TurnOver();
            turnoverForm.ShowDialog();
        }

    }
}
